<?php
App::uses('AppController', 'Controller');
/**
 * Trieuchungs Controller
 *
 * @property Trieuchung $Trieuchung
 * @property PaginatorComponent $Paginator
 */
class TrieuchungsController extends AppController {

/**
 * Components
 *
 * @var array
 */
	public $components = array('Paginator');

/**
 * index method
 *
 * @return void
 */
	public function admin_index() {
		$this->Trieuchung->recursive = 0;
		$this->set('trieuchungs', $this->Paginator->paginate());
	}

/**
 * view method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function view($id = null) {
		if (!$this->Trieuchung->exists($id)) {
			throw new NotFoundException(__('Invalid trieuchung'));
		}
		$options = array('conditions' => array('Trieuchung.' . $this->Trieuchung->primaryKey => $id));
		$this->set('trieuchung', $this->Trieuchung->find('first', $options));
	}

/**
 * add method
 *
 * @return void
 */
	public function admin_add() {
		if ($this->request->is('post')) {
			$this->Trieuchung->create();
			if ($this->Trieuchung->save($this->request->data)) {
				$this->Session->setFlash(__('Thêm triệu chứng thành công'),'backend/green',array('redirect'=>''));
				return $this->redirect(array('action' => 'admin_index'));
			} else {
				$this->Session->setFlash(__('Lỗi save dữ liệu'),'backend/red',array('redirect'=>''));
			}
		}
        $this->loadModel('Bophan');
        $bophans = $this->Bophan->find('list',array('fields'=>array('id','ten_bophan')));
        $this->set(compact('bophans'));
	}

/**
 * edit method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function admin_edit($id = null) {
		if (!$this->Trieuchung->exists($id)) {
			throw new NotFoundException(__('Invalid trieuchung'));
		}
		if ($this->request->is('post') || $this->request->is('put')) {
			if ($this->Trieuchung->save($this->request->data)) {
				$this->Session->setFlash(__('Sửa thông tin thành công'),'backend/green',array('redirect'=>''));
				return $this->redirect(array('action' => 'admin_index'));
			} else {
				$this->Session->setFlash(__('Lỗi lưu thông tin '),'backend/red',array('redirect'=>''));
			}
		} else {
			$options = array('conditions' => array('Trieuchung.' . $this->Trieuchung->primaryKey => $id));
			$this->request->data = $this->Trieuchung->find('first', $options);
		}
        $this->loadModel('Bophan');
        $bophans = $this->Bophan->find('list',array('fields'=>array('id','ten_bophan')));
        $this->set(compact('bophans'));
	}

/**
 * delete method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function admin_delete($id = null) {
		$this->Trieuchung->id = $id;
		if (!$this->Trieuchung->exists()) {
			throw new NotFoundException(__('Invalid trieuchung'));
		}
		$this->request->onlyAllow('get', 'delete');
		if ($this->Trieuchung->delete()) {
			$this->Session->setFlash(__('Xóa thông tin thành công'),'backend/green',array('redirect'=>''));
		} else {
			$this->Session->setFlash(__('Lỗi xóa dữ liêu'),'backend/red',array('redirect'=>''));
		}
		return $this->redirect(array('action' => 'admin_index'));
	}}
